<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改种质资源')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-germplasm-edit" th:object="${bizGermplasm}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">编号：</label>
                <div class="col-sm-8">
                    <input name="code" th:field="*{code}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">种名：</label>
                <div class="col-sm-8">
                    <input name="specificName" th:field="*{specificName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">种拉丁名：</label>
                <div class="col-sm-8">
                    <input name="latinName" th:field="*{latinName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">经度：</label>
                <div class="col-sm-8">
                    <input name="longitude" th:field="*{longitude}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">纬度：</label>
                <div class="col-sm-8">
                    <input name="latitude" th:field="*{latitude}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">海拔(单位：米)：</label>
                <div class="col-sm-8">
                    <input name="elevation" th:field="*{elevation}" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">生活型：</label>
                <div class="col-sm-8">
                    <input name="lifeForm" th:field="*{lifeForm}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">药材名：</label>
                <div class="col-sm-8">
                    <input name="medicinalName" th:field="*{medicinalName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">采集地址：</label>
                <div class="col-sm-8">
                    <input name="collectionAddress" th:field="*{collectionAddress}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">采集时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="collectionTime" th:value="${#dates.format(bizGermplasm.collectionTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">种质特征：</label>
                <div class="col-sm-8">
                    <input name="characteristics" th:field="*{characteristics}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">种质保存位置：</label>
                <div class="col-sm-8">
                    <input name="preservationLocation" th:field="*{preservationLocation}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">种质资源植物照片：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="plantPhotograph" th:field="*{plantPhotograph}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="plantPhotograph" name="files" type="file" multiple>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">凭证标本：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="voucherSpecimen" th:field="*{voucherSpecimen}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="voucherSpecimen" name="files" type="file" multiple>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" th:field="*{remark}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "biz/germplasm";
        $("#form-germplasm-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-germplasm-edit').serialize());
            }
        }

        $("input[name='collectionTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(".file-upload").each(function (i) {
            var urls = $("input[name='" + this.id + "']").val();
            var val = urls.length > 0 ? urls.split(",") : [];
            $(this).fileinput({
                'uploadUrl': ctx + 'common/uploads',
                initialPreviewAsData: true,
                initialPreview: val,
                // allowedPreviewTypes: ['image','pdf','txt'],
                maxFileCount: 9,
                // autoReplace: false,
                uploadAsync: false
            }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.urls)
                // $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
                // var rsp = data.response;
                // log.info("return urls：" + rsp.urls)
                // log.info("reutrn fileNames：" + rsp.fileNames)
                // log.info("reutrn newFileNames：" + rsp.newFileNames)
                // log.info("return originalFilenames：" + rsp.originalFilenames)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

    </script>
</body>
</html>